<?php
    $aRoleName = unserialize(ROLE_NAME);
    $cur_user_id = $this->session->userdata('user_id');
?>

<div class="row">
	<div class="col-md-12">
		<h1>Người dùng <small>Quản lý danh sách người dùng</small></h1>
		<ol class="breadcrumb">
            <li><a href="<?php echo admin_page_url(); ?>"><i class="fa fa-dashboard"></i> Dashboard</a></li>
            <li class="active"><i class="fa fa-table"></i> Danh sách người dùng hiện có</li>
        </ol>
    </div>
</div>

<div class="row">
    <div class="col-md-6 col-xs-12">
        <form method="get" action="<?php echo admin_page_url(USER_SLUG.'/tim-kiem'); ?>" enctype="multipart/form-data">
            <div class="input-group">
                <input type="text" class="form-control" name="s" value="<?php echo isset($searchkey)?$searchkey:''; ?>" placeholder="Tìm kiếm" />
                <span class="input-group-btn">
                    <button class="btn btn-success" type="submit"><i class="fa fa-search"></i> Tìm kiếm!</button>
                </span>
            </div><!-- /input-group -->
        </form>
    </div>

    <div class="col-md-6 col-xs-12">
        <p class="pull-right">
            <a class="btn btn-success" href="<?php echo admin_page_url('nguoi-dung/them'); ?>">
                <i class="glyphicon glyphicon-plus-sign"></i> Thêm người dùng
            </a>
        </p>
    </div>

    <div class="col-md-12 col-xs-12"><?php echo isset($pagingBar)?$pagingBar:''; ?></div>
</div>

<div class="row mgt10">
    <div class="col-md-12 col-xs-12">
        <div class="table-responsive">
            <table class="table table-bordered table-hover tablesorter item-list" data-href='<?php echo admin_page_url(USER_SLUG . '/cap-nhat/trang-thai'); ?>'>
                <thead>
                    <tr>
                        <th class="header"># <i class="fa fa-sort"></i></th>
                        <th class="header">Hình ảnh</th>
                        <th class="header">Thông tin<br /><small><i class="normal">(Cấp bậc, tên đăng nhập, email)</i></small></th>
                        <th class="header">Họ tên <i class="fa fa-sort"></i></th>
                        <th class="header">Địa chỉ <i class="fa fa-sort"</th>
                        <th class="header">Điện thoại <i class="fa fa-sort"</th>
                        <th class="header">Ngày sinh <i class="fa fa-sort"</th>
                        <th class="header">Giới tính <i class="fa fa-sort"</th>
                        <th class="header">Hoạt động <i class="fa fa-sort"</th>
                        <th class="header">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</th>
                    </tr>
                </thead>
                <tbody>
                    <?php foreach($aUser as $index=>$u) { ?>
                    <?php
                        $active_class = '';
                        $edit_link = admin_page_url(USER_SLUG.'/cap-nhat', array('u'=>$this->encrypt->encode($u->getId())));
                        if($u->getId() == $cur_user_id) {
                            $active_class = 'grey';
                            $edit_link = page_url(ACCOUNT_SLUG);
                        }
                    ?>
                    <tr class="row-<?php echo $aRoleName[$u->role]; ?>" data-id='<?php echo $this->encrypt->encode($u->id); ?>'>
                        <th><?php echo $index+1; ?></th>
                        <td>
                            <?php
                            $img_name = '';
                            if($u->getImage()!=NULL){
                                $img_name = avatar_upload($u->getImage(), $u->image_folder);
                            } else {
                                $img_name = 'role-';
                                switch ($u->role) {
                                    case ROLE_ADMIN      : $img_name .= 'admin';     break;
                                    case ROLE_MOD        : $img_name .= 'mod';       break;
                                    case ROLE_SHOP_OWNER : $img_name .= 'user';      break;
                                    case ROLE_ADVERTISER : $img_name .= 'advertise'; break;
                                    default: break;
                                }
                                $img_name = assets('images/'.$img_name.'.png', true);
                            }
                            ?>
                            <img title="<?php echo $u->full_name; ?>" alt="<?php echo $u->full_name; ?>" src="<?php echo $img_name; ?>" />
                        </td>
                        <td>
                            <p>
                                <?php
                                $roleClass = '';
                                if($u->role==ROLE_ADMIN){ $roleClass = 'admin'; }
                                elseif($u->role==ROLE_MOD){ $roleClass = 'mod'; }
                                elseif($u->role==ROLE_SHOP_OWNER){ $roleClass = 'shop-owner'; }
                                elseif($u->role==ROLE_ADVERTISER){ $roleClass = 'advertiser'; }
                                ?>
                                <span class="<?php echo $roleClass; ?>"><?php echo $aRoleName[$u->role]; ?></span>
                            </p>
                            <p><strong><?php echo $u->username; ?></strong></p>
                            <p><?php echo $u->email; ?></p>
                        </td>
                        <td><?php echo $u->full_name; ?></td>
                        <td><?php echo $u->address; ?></td>
                        <td><?php echo $u->phone; ?></td>
                        <td><?php echo $u->birthday; ?></td>
                        <td><?php echo $u->gender==GENDER_MALE?'Nam':'Nữ'; ?></td>
                        <td>
                            <div class="checkbox inline-table mgr10">
                                <input id="chk-active-<?php echo $u->id; ?>"
                                    class="input-user-active-flg lb-toggle <?php echo $active_class; ?>"
                                    data-name="active_flg"
                                    type="checkbox"
                                    <?php if($u->active_flg!=NULL && $u->active_flg==1){ echo "checked='checked'"; } ?>
                                />
                                <label for="chk-active-<?php echo $u->id; ?>"></label>
                            </div>
                        </td>
                        <td>
                            <div class="btn-group">
                                <a class="btn btn-success" href="<?php echo $edit_link; ?>"><i class='glyphicon glyphicon-wrench'></i></a>
                                <button type="button" class="btn btn-success dropdown-toggle" data-toggle="dropdown">
                                    <span class="caret"></span>
                                    <span class="sr-only">Toggle Dropdown</span>
                                </button>
                                <ul class="dropdown-menu" role="menu">
                                    <li>
                                        <a class="btn-reset-pass" href="<?php echo admin_page_url(USER_SLUG . '/dat-lai-mk'); ?>" data-id='<?php echo $this->encrypt->encode($u->id); ?>'>
                                            Đặt lại mật khẩu
                                        </a>
                                    </li>
                                </ul>
                            </div>
                        </td>
                    </tr>
                    <?php } ?>
                </tbody>
            </table>
        </div>
    </div>
</div>